package response

import (
	"net/http"

	"go-pioneer/pkg/errorcode"

	"github.com/gin-gonic/gin"
)

type Response struct {
	ctx *gin.Context
}

func NewResponse(ctx *gin.Context) *Response {
	return &Response{
		ctx: ctx,
	}
}

func (r *Response) ToErrorResponse(err *errorcode.Error) {
	r.ctx.JSON(http.StatusBadRequest, gin.H{
		"code": err.Code,
		"msg":  err.Msg(),
	})
}

func (r *Response) ToResponseSuccess(data interface{}) {
	r.ctx.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "success",
		"data": data,
	})
}
